package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.PaymentType;
import com.atguigu.lease.model.entity.RoomPaymentType;
import com.atguigu.lease.web.app.mapper.RoomPaymentTypeMapper;
import com.atguigu.lease.web.app.service.PaymentTypeService;
import com.atguigu.lease.web.app.service.RoomPaymentTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

/**
* @author liubo
* @description 针对表【room_payment_type(房间&支付方式关联表)】的数据库操作Service实现
* @createDate 2023-07-26 11:12:39
*/
@Service
public class RoomPaymentTypeServiceImpl extends ServiceImpl<RoomPaymentTypeMapper, RoomPaymentType>
    implements RoomPaymentTypeService{
@Autowired
private RoomPaymentTypeMapper roomPaymentTypeMapper;
@Autowired
    PaymentTypeService paymentTypeService;
    @Override
    public List<PaymentType> selectListByRoomId(Long id) {
        List<RoomPaymentType> roomPaymentTypes = roomPaymentTypeMapper.selectList(new LambdaQueryWrapper<RoomPaymentType>().eq(RoomPaymentType::getRoomId, id));
        HashSet<PaymentType> paymentTypes = new HashSet<>();
        roomPaymentTypes.forEach(roomPaymentType -> {

            PaymentType byId = paymentTypeService.getById(roomPaymentType.getPaymentTypeId());
            paymentTypes.add(byId);


        });
        return new ArrayList<>(paymentTypes);
    }
}




